<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>Git学习笔记 | 净土</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="A blog of howiefh.">
<meta property="og:type" content="article">
<meta property="og:title" content="Git学习笔记">
<meta property="og:url" content="http://howiefh.github.io/2013/05/02/git-note/index.html">
<meta property="og:site_name" content="净土">
<meta property="og:description" content="A blog of howiefh.">
<meta property="og:updated_time" content="2015-03-05T14:43:18.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="Git学习笔记">
<meta name="twitter:description" content="A blog of howiefh.">
  
    <link rel="alternative" href="/atom.xml" title="净土" type="application/atom+xml">
  
  
    <link rel="icon" href="/favicon.ico">
  
  <link href="http://fonts.useso.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="/css/style.css" type="text/css">
  
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

ga('create', 'UA-40492061-1', 'auto');
ga('send', 'pageview');

</script>


  
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "//hm.baidu.com/hm.js?56d2899c5e919fbf4a7b00de5d1c31dd";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>


</head>

<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">净土</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/" id="subtitle">乐不在外而在心，心以为乐，则是境皆乐；心以为苦，则无境不苦。</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
      </nav>
      <nav id="sub-nav">
        
          <a id="nav-github-link" class="nav-icon" href="https://github.com/howiefh" title="Github" target="_blank"></a>
        
        
          <a id="nav-rss-link" class="nav-icon" href="/atom.xml" title="RSS Feed" target="_blank"></a>
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="sitesearch" value="http://howiefh.github.io"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-git-note" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    
<a href="/2013/05/02/git-note/" class="article-date">
  <time datetime="2013-05-02T10:31:29.000Z" itemprop="datePublished">2013-05-02</time>
</a>


    
  <div class="article-category">
    <a class="article-category-link" href="/categories/Git/">Git</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      Git学习笔记
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
		
		<div id="toc" class="toc-article">
			<h2 class="toc-title"><span>Contents</span></h2>
		
			<ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#git别名"><span class="toc-number">1.</span> <span class="toc-text">git别名</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#忽略文件"><span class="toc-number">2.</span> <span class="toc-text">忽略文件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#添加文件到暂存区"><span class="toc-number">3.</span> <span class="toc-text">添加文件到暂存区</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#提交修改"><span class="toc-number">4.</span> <span class="toc-text">提交修改</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#查看工作目录状态"><span class="toc-number">5.</span> <span class="toc-text">查看工作目录状态</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#查看文件改动"><span class="toc-number">6.</span> <span class="toc-text">查看文件改动</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#查看提交信息"><span class="toc-number">7.</span> <span class="toc-text">查看提交信息</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#反转提交"><span class="toc-number">8.</span> <span class="toc-text">反转提交</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#克隆远程版本库"><span class="toc-number">9.</span> <span class="toc-text">克隆远程版本库</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#创建分支"><span class="toc-number">10.</span> <span class="toc-text">创建分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#切换分支"><span class="toc-number">11.</span> <span class="toc-text">切换分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#重命名分支"><span class="toc-number">12.</span> <span class="toc-text">重命名分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#合并分支"><span class="toc-number">13.</span> <span class="toc-text">合并分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#删除分支"><span class="toc-number">14.</span> <span class="toc-text">删除分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#打标签"><span class="toc-number">15.</span> <span class="toc-text">打标签</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#创建归档文件"><span class="toc-number">16.</span> <span class="toc-text">创建归档文件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#文件重命名和移动"><span class="toc-number">17.</span> <span class="toc-text">文件重命名和移动</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#合并其他remote上面的更新"><span class="toc-number">18.</span> <span class="toc-text">合并其他remote上面的更新</span></a></li></ol>
		
		</div>
		
        <h2 id="git别名">git别名</h2><figure class="highlight armasm"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="label">git</span> config --<span class="preprocessor">global</span> <span class="preprocessor">alias</span>.ci <span class="string">"commit"</span></span><br><span class="line"><span class="label">git</span> config --<span class="preprocessor">global</span> <span class="preprocessor">alias</span>.co <span class="string">"chechout"</span></span><br><span class="line"><span class="label">git</span> config --<span class="preprocessor">global</span> <span class="preprocessor">alias</span>.st <span class="string">"status"</span></span><br><span class="line"><span class="label">git</span> config --<span class="preprocessor">global</span> <span class="preprocessor">alias</span>.<span class="keyword">br </span><span class="string">"branch"</span></span><br></pre></td></tr></table></figure>
<h2 id="忽略文件">忽略文件</h2><p>如果是版本库级别的忽略用<code>.gitignore</code>；如果仅仅是个人的忽略用<code>.git/info/exclude</code>，不会将此设置传播出去  </p>
<p>忽略规则:<br><figure class="highlight cmake"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 此为注释 – 将被 Git 忽略</span></span><br><span class="line">*.a		<span class="comment"># 忽略所有 .a 结尾的文件</span></span><br><span class="line">!lib.a		<span class="comment"># 但 lib.a 除外</span></span><br><span class="line">/TODO		<span class="comment"># 仅仅忽略项目根目录下的 <span class="doctag"><span class="keyword">TODO</span></span> 文件，不包括 subdir/<span class="doctag"><span class="keyword">TODO</span></span></span></span><br><span class="line">build/		<span class="comment"># 忽略 build/ 目录下的所有文件</span></span><br><span class="line">doc/*.txt	<span class="comment"># 会忽略 doc/notes.txt 但不包括 doc/server/arch.txt</span></span><br></pre></td></tr></table></figure></p>
<a id="more"></a>
<h2 id="添加文件到暂存区">添加文件到暂存区</h2><p>基本命令 <code>git add</code>；<br>交互式模式 <code>git add -i</code>；<br>补丁模式 <code>git add -p</code></p>
<h2 id="提交修改">提交修改</h2><p>先暂存，后提交<br><figure class="highlight livecodeserver"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">add</span> <span class="built_in">files</span></span><br><span class="line">git commit -m <span class="string">".."</span></span><br></pre></td></tr></table></figure></p>
<p>直接提交 <code>git commit -m &quot;..&quot; -a</code>； 或者 <code>git commit -m &quot;..&quot; files</code></p>
<ul>
<li>多个-m可以换行  </li>
<li>提交留言至少应该体现出进行本次修改的原因  </li>
<li>增补提交<br>  对于提交后发现一些小问题的情况，可以使用—amend。只能针对最后一个提交。<br>  编辑contact.html添加一个链接 <code>git commit -m &quot;add link to google&quot; -a</code><br>  之后修改链接地址 <code>git commit -C HEAD -a --amend</code><br>  -C使复用制定提交（HEAD）的提交留言。-c会打开默认编辑器。增补提交是修正上次提交，git log 会发现只有增补提交的提交名称，而没有上次的。</li>
</ul>
<h2 id="查看工作目录状态">查看工作目录状态</h2><figure class="highlight fortran"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="keyword">status</span></span><br></pre></td></tr></table></figure>
<h2 id="查看文件改动">查看文件改动</h2><p>比较工作目录和暂存区 <code>git diff</code>；<br>比较暂存区和版本库 <code>git diff --cached</code>；<br>比较工作目录和版本库 <code>git diff HEAD</code></p>
<h2 id="查看提交信息">查看提交信息</h2><p>常用命令 <code>git log</code><br>快速查看历史记录 <code>git log --pretty=oneline</code><br>记录比较多时，可以使用jk等vi的命令向下向上查看</p>
<figure class="highlight applescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">git <span class="command">log</span> -p  <span class="comment"># 添加-p选项可以显示版本间代码差异</span></span><br><span class="line">git <span class="command">log</span> -<span class="number">1</span>  <span class="comment"># 显示一个</span></span><br><span class="line">git <span class="command">log</span> -<span class="number">2</span>  <span class="comment"># 查看近两次提交</span></span><br><span class="line">git <span class="command">log</span> a8b8a42  <span class="comment"># 查看提交名称为a8b8a42及其之前的提交，至少应该有四位</span></span><br></pre></td></tr></table></figure>
<p>按范围查看提交信息<br><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">log</span> --since=<span class="string">"5 hours"</span>  <span class="comment"># 查看5小时以内的提交</span></span><br><span class="line">git <span class="built_in">log</span> --before=<span class="string">"5 hours"</span> <span class="comment"># 查看5小时之前的提交</span></span><br></pre></td></tr></table></figure></p>
<p>可以接受的的时间格式：3 hours, 5 minutes, 1 minute, 2013-4-13, 2013.4.13, 2013-4.13<br><figure class="highlight perl"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git <span class="keyword">log</span> <span class="number">8</span>d0a22b..a8b8a42    <span class="comment"># 查看提交名称在8d0a22b和a8b8a42之间的提交，不包括起点，只包括终点</span></span><br><span class="line">git <span class="keyword">log</span> <span class="number">8</span>d0a22b..HEAD       <span class="comment"># 查看提交名称8d0a22b到当前分支末梢的最新版本，也可以不输HEAD</span></span><br><span class="line">git <span class="keyword">log</span> --pretty=<span class="keyword">format</span>:<span class="string">"<span class="variable">%h</span> <span class="variable">%s</span>"</span> <span class="number">1.0</span>..HEAD <span class="comment"># 查看标签1.0到当前分支末梢的最新版本</span></span><br></pre></td></tr></table></figure></p>
<p>^:一个脱字符作用相遇回溯一个版本 8d0a22b^是指8d0a22b之前的那个版本<br>~n:波浪线加数字是指回溯n个版本。8d0a22b~1是指8d0a22b的父节点<br>以下命令执行结果相同<br><figure class="highlight applescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">git <span class="command">log</span> -<span class="number">1</span> HEAD^^^</span><br><span class="line">git <span class="command">log</span> -<span class="number">1</span> HEAD^~<span class="number">2</span></span><br><span class="line">git <span class="command">log</span> -<span class="number">1</span> HEAD~<span class="number">1</span>^^</span><br><span class="line">git <span class="command">log</span> -<span class="number">1</span> HEAD~<span class="number">3</span></span><br></pre></td></tr></table></figure></p>
<p>查看版本之间的差异<br><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">git</span> diff 8d0a22b      <span class="comment"># 默认第二个参数不写的话就是HEAD</span></span><br><span class="line">git diff --stat <span class="number">1</span>.<span class="number">0</span>   <span class="comment"># --stat可以统计改动的代码量，同样第二个参数不写就是HEAD</span></span><br></pre></td></tr></table></figure></p>
<p>查看代码块的历史信息<br><figure class="highlight armasm"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="label">git</span> <span class="keyword">blame </span>index.html</span><br></pre></td></tr></table></figure></p>
<p>输出：<br><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">^<span class="tag">a8b8a42</span> (<span class="tag">howiefh</span> 2013<span class="tag">-04-13</span> 19<span class="pseudo">:18</span><span class="pseudo">:35</span> +0800  1) &lt;<span class="tag">html</span>&gt;</span><br><span class="line"><span class="tag">e207eaa0</span> (<span class="tag">howiefh</span> 2013<span class="tag">-04-13</span> 19<span class="pseudo">:30</span><span class="pseudo">:12</span> +0800  2)         &lt;<span class="tag">head</span>&gt;</span><br></pre></td></tr></table></figure></p>
<p>有脱字符的表示版本库中的第一个提交<br>可以限定查看范围<br><figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">git blame -L <span class="number">12</span>,<span class="number">13</span> index<span class="class">.html</span></span><br><span class="line">git blame -L <span class="number">12</span>,+<span class="number">2</span> index<span class="class">.html</span></span><br><span class="line">git blame -L <span class="number">12</span>,-<span class="number">2</span> index<span class="class">.html</span></span><br><span class="line">git blame -L <span class="string">"/&lt;\/body&gt;/"</span>,+<span class="number">2</span> index<span class="class">.html</span></span><br><span class="line">git blame -L <span class="string">"/&lt;\/body&gt;/"</span>,-<span class="number">2</span> <span class="number">8</span>d0a22b^ -- index.html</span><br></pre></td></tr></table></figure></p>
<p>跟踪内容<br>创建文件original.txt写入三行，并再复制这三行<br><figure class="highlight armasm"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="label">git</span> <span class="keyword">blame </span>original.txt</span><br><span class="line"><span class="label">git</span> <span class="keyword">blame </span>-M original.txt</span><br></pre></td></tr></table></figure></p>
<p>后者显示的所有提交名称相同，因为git检测到了重复的内容<br>复制文件original.txt并重命名为copy.txt<br><figure class="highlight mathematica"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git blame -<span class="keyword">C</span> -<span class="keyword">C</span> copy.txt</span><br></pre></td></tr></table></figure></p>
<p>显示出事提交名称和初始文件名original.txt<br><figure class="highlight applescript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="command">log</span> -C -C -<span class="number">1</span> -p		<span class="comment"># 可以检测到复制信息</span></span><br></pre></td></tr></table></figure></p>
<h2 id="反转提交">反转提交</h2><figure class="highlight stata"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git revert -<span class="keyword">n</span> HEAD     # -<span class="keyword">n</span>选项git 会暂存所有变更，而不立即提交，--<span class="keyword">no</span>-<span class="keyword">edit</span>不打开编辑器</span><br><span class="line">git revert -<span class="keyword">n</span> 49005c1 </span><br><span class="line">git commit</span><br></pre></td></tr></table></figure>
<p>复位<br><figure class="highlight perl"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git <span class="keyword">reset</span> --hard HEAD^		<span class="comment"># 复位到HEAD的父节点</span></span><br><span class="line">git <span class="keyword">reset</span> --hard HEAD~<span class="number">3</span>		<span class="comment"># 复位到HEAD的曾祖父节点</span></span><br></pre></td></tr></table></figure></p>
<p><strong>revert vs. reset</strong><br>revert相对安全，是对某一次提交undo，并且保留提交历史。<br>reset相对比较危险，要对某一次提交undo则其后的所有提交都会undo，不保留历史，永久性的。<br>改写历史记录<br>重新排序<br><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">git</span> rebase -i HEAD~<span class="number">3</span>   <span class="comment"># 之后在打开的编辑器中改变顺序</span></span><br></pre></td></tr></table></figure></p>
<p>将多个提交压合成一个提交<br><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">git</span> rebase -i 0bb3dfb^  <span class="comment"># 将要修改要合并的另一个记录移动到0bb3dfb后，并将其前面的pick改为squash</span></span><br></pre></td></tr></table></figure></p>
<p>将一个提交分解成多个提交<br><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">git</span> rebase -i HEAD~<span class="number">4</span>  <span class="comment"># 在打开的编辑器中将要分解的记录前的pick改为edit，保存退出，git reset HEAD^，git diff，对文件修改并分别提交，git rebase --continue</span></span><br></pre></td></tr></table></figure></p>
<h2 id="克隆远程版本库">克隆远程版本库</h2><figure class="highlight groovy"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git clone <span class="string">git:</span><span class="comment">//github.com/tswicegood/mysite-chp6.git</span></span><br></pre></td></tr></table></figure>
<p>克隆后本地只有主分支，可以通过<code>git branch -a</code> 查看所有分支，其它分支是隐藏的，可以通过<code>git checkout -b experimental origin/experimental</code>创建并切换分支。<br>版本库同步<br><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git fetch</span><br><span class="line">git pull <span class="tag">&lt;<span class="title">远程版本库名称</span>&gt;</span> <span class="tag">&lt;<span class="title">需要拖入的远程版本库的分支名</span>&gt;</span></span><br></pre></td></tr></table></figure></p>
<p><strong>fetch vs pull</strong></p>
<ol>
<li><p>git fetch：相当于是从远程获取最新版本到本地，不会自动merge</p>
 <figure class="highlight fortran"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git fetch origin master</span><br><span class="line">git <span class="built_in">log</span> -p master..origin/master</span><br><span class="line">git <span class="built_in">merge</span> origin/master</span><br></pre></td></tr></table></figure>
<p> 以上命令的含义：<br> 首先从远程的origin的master主分支下载最新的版本到origin/master分支上<br> 然后比较本地的master分支和origin/master分支的差别<br> 最后进行合并</p>
<p> 上述过程其实可以用以下更清晰的方式来进行：</p>
 <figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">git</span> <span class="tag">fetch</span> <span class="tag">origin</span> <span class="rule"><span class="attribute">master</span>:<span class="value">tmp</span><br><span class="line">git diff tmp </span><br><span class="line">git merge tmp</span></span></span><br></pre></td></tr></table></figure>
<p> 从远程获取最新的版本到本地的tmp分支上<br> 之后再进行比较合并</p>
</li>
<li><p>git pull：相当于是从远程获取最新版本并merge到本地</p>
 <figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">git</span> pull origin master</span><br></pre></td></tr></table></figure>
<p> 上述命令其实相当于git fetch 和 git merge。在实际使用中，git fetch更安全一些，因为在merge前，我们可以查看更新情况，然后再决定是否合并。</p>
</li>
</ol>
<p>给远程版本库起别名<br><figure class="highlight vim"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git remote <span class="built_in">add</span> origin gi<span class="variable">t:</span>//github.<span class="keyword">com</span>/tswicegood/mysite.git</span><br></pre></td></tr></table></figure></p>
<p>推入远程版本库<br><figure class="highlight armasm"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="label">git</span> <span class="keyword">push </span>origin master</span><br></pre></td></tr></table></figure></p>
<p>查看本地创建的全部远程版本库别名<br><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">git</span> remote</span><br></pre></td></tr></table></figure></p>
<p>查看某个远程版本库 的详细信息<br><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git remote show <span class="tag">&lt;<span class="title">版本库别名</span>&gt;</span></span><br></pre></td></tr></table></figure><br>删除版本库别名<br><figure class="highlight xml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git remote rm <span class="tag">&lt;<span class="title">版本库别名</span>&gt;</span></span><br></pre></td></tr></table></figure></p>
<h2 id="创建分支">创建分支</h2><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">git</span> <span class="tag">branch</span> <span class="tag">RB_1</span><span class="class">.0</span> <span class="tag">master</span>  # <span class="tag">RB_1</span><span class="class">.0</span>新分支名，<span class="tag">master</span> 主干</span><br><span class="line"><span class="tag">git</span> <span class="tag">branch</span> <span class="tag">RB_1</span><span class="class">.0</span><span class="class">.1</span> 1<span class="class">.0</span>   # 1<span class="class">.0</span>是打过的标签</span><br></pre></td></tr></table></figure>
<p>以下情况创建分支</p>
<pre><code><span class="bullet">* </span>试验性修改
<span class="bullet">* </span>增加新功能
<span class="bullet">* </span>bug修复
</code></pre><h2 id="切换分支">切换分支</h2><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">git</span> <span class="tag">checkout</span> <span class="tag">RB_1</span><span class="class">.0</span></span><br></pre></td></tr></table></figure>
<p>创建分支并检出该分支<br><figure class="highlight actionscript"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git chechout -b <span class="keyword">new</span> master  # <span class="keyword">new</span>是新分支名，master是告诉git，不是从当前分支，而是从主分支上创建新分支，即基于主分支末梢创建新分支</span><br></pre></td></tr></table></figure></p>
<h2 id="重命名分支">重命名分支</h2><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">git</span> branch -m master mymaster  <span class="comment"># master是就分支名，mymaster是新分支名</span></span><br></pre></td></tr></table></figure>
<p>新分支名和已有的分支名相同时，重命名不会成功。<br><figure class="highlight armasm"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="label">git</span> <span class="keyword">branch </span>-M master mymaster</span><br></pre></td></tr></table></figure></p>
<p>可以强制重命名，并覆盖已有分支名称，需小心使用</p>
<h2 id="合并分支">合并分支</h2><p>直接合并<br><figure class="highlight livecodeserver"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git chechout master</span><br><span class="line">git <span class="built_in">merge</span> alternate    <span class="comment"># 将分支alternate的修改合并进master</span></span><br></pre></td></tr></table></figure></p>
<p>压合合并<br><figure class="highlight livecodeserver"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git chechout master</span><br><span class="line">git <span class="built_in">merge</span> <span class="comment">--squash contact</span></span><br><span class="line">git commit -m <span class="string">"add contact file"</span>   <span class="comment"># 将分支contact多次提交的修改合并为一次提交</span></span><br></pre></td></tr></table></figure></p>
<p>拣选合并<br>拣选一次提交进行合并<br><figure class="highlight dns"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git chechout master</span><br><span class="line">git cherry-pick <span class="number">3d5a506</span></span><br></pre></td></tr></table></figure></p>
<p>拣选多个提交<br><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">git</span> checkout master</span><br><span class="line">git cherry-pick -n 3d5a506  <span class="comment"># 3d5a506是提交名称   </span></span><br><span class="line">git commit   <span class="comment"># 不需要-m参数</span></span><br></pre></td></tr></table></figure></p>
<p>冲突处理<br>如果在不同分支上对同一文件的同一文本块进行不同的修改，合并这两个不同分支时会有冲突<br><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">git</span> mergetool</span><br></pre></td></tr></table></figure></p>
<p>选择工具来人工处理冲突<br><figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">git</span> commit     <span class="comment"># 不需要-m参数</span></span><br></pre></td></tr></table></figure></p>
<p>把RB_1.0分支上所做的修改合并到主分支上<br><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">git</span> <span class="tag">chechout</span> <span class="tag">master</span></span><br><span class="line"><span class="tag">git</span> <span class="tag">rebase</span> <span class="tag">RB_1</span><span class="class">.0</span></span><br></pre></td></tr></table></figure></p>
<h2 id="删除分支">删除分支</h2><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git branch <span class="operator">-d</span> RB_1.<span class="number">0</span> 	<span class="comment"># 仅仅是删除了分知名，该分支的内容并没有被删除</span></span><br></pre></td></tr></table></figure>
<p>如果分支还没有合并回当前分支，删除不会成功<br><figure class="highlight armasm"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="label">git</span> <span class="keyword">branch </span>-D RB_1.<span class="number">0</span></span><br></pre></td></tr></table></figure></p>
<p>可以强制删除分支</p>
<h2 id="打标签">打标签</h2><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">git</span> <span class="tag">tag</span> 1<span class="class">.0</span> <span class="tag">RB_1</span><span class="class">.0</span></span><br></pre></td></tr></table></figure>
<p>查看标签<br><figure class="highlight lasso"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">git <span class="built_in">tag</span></span><br></pre></td></tr></table></figure></p>
<h2 id="创建归档文件">创建归档文件</h2><figure class="highlight brainfuck"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">git</span> <span class="comment">archive</span> <span class="literal">-</span><span class="literal">-</span><span class="comment">format=tar</span> <span class="literal">-</span><span class="literal">-</span><span class="comment">prefix=mysite</span><span class="literal">-</span><span class="comment">1</span><span class="string">.</span><span class="comment">0/</span> <span class="comment">1</span><span class="string">.</span><span class="comment">0</span> <span class="comment">|</span> <span class="comment">gzip</span> &gt; <span class="comment">mysite</span><span class="literal">-</span><span class="comment">1</span><span class="string">.</span><span class="comment">0</span><span class="string">.</span><span class="comment">tar</span><span class="string">.</span><span class="comment">gz</span></span><br><span class="line"><span class="comment">git</span> <span class="comment">archive</span> <span class="literal">-</span><span class="literal">-</span><span class="comment">format=zip</span> <span class="literal">-</span><span class="literal">-</span><span class="comment">prefix=mysite</span><span class="literal">-</span><span class="comment">1</span><span class="string">.</span><span class="comment">0/</span> <span class="comment">1</span><span class="string">.</span><span class="comment">0</span> &gt; <span class="comment">mysite</span><span class="literal">-</span><span class="comment">1</span><span class="string">.</span><span class="comment">0</span><span class="string">.</span><span class="comment">zip</span></span><br></pre></td></tr></table></figure>
<h2 id="文件重命名和移动">文件重命名和移动</h2><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">git</span> <span class="tag">mv</span> <span class="tag">index</span><span class="class">.html</span> <span class="tag">hello</span><span class="class">.html</span></span><br></pre></td></tr></table></figure>
<h2 id="合并其他remote上面的更新"><a href="http://huacnlee.com/blog/merge-other-remote-commits-to-current-fork-with-git/" target="_blank" rel="external">合并其他remote上面的更新</a></h2><p>在 Github 上面 Fork 别人的项目时，我们常常会遇到主项目有了更新，这个时候怎么把主项目的更新合并到自己 Fork 的版本里面来呢？ </p>
<figure class="highlight groovy"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"># 我先吧 tualatrix Fork 的版本获取到本地</span><br><span class="line"><span class="regexp">~/work $ git clone git:/</span><span class="regexp">/github.com/</span>tualatrix/ruby-china.git</span><br><span class="line">~/work $ cd ruby-china</span><br><span class="line"><span class="regexp">~/work/</span>ruby-china &lt;master&gt; $ git remote</span><br><span class="line">origin</span><br><span class="line"># 添加 huacnlee (也就是主项目的 remote 地址)</span><br><span class="line"><span class="regexp">~/work/</span>ruby-china &lt;master&gt; $ git remote add huacnlee <span class="string">git:</span><span class="comment">//github.com/huacnlee/ruby-china.git</span></span><br><span class="line"># 用 fetch 命令获取 huacnlee 的所有分支</span><br><span class="line"><span class="regexp">~/work/</span>ruby-china &lt;master&gt; $ git fetch huacnlee</span><br><span class="line"><span class="string">remote:</span> Counting <span class="string">objects:</span> <span class="number">499</span>, done.</span><br><span class="line"><span class="string">remote:</span> Compressing <span class="string">objects:</span> <span class="number">100</span>% (<span class="number">143</span>/<span class="number">143</span>), done.</span><br><span class="line"><span class="string">remote:</span> Total <span class="number">315</span> (delta <span class="number">211</span>), reused <span class="number">253</span> (delta <span class="number">172</span>)</span><br><span class="line">Receiving <span class="string">objects:</span> <span class="number">100</span>% (<span class="number">315</span><span class="regexp">/315), 190.17 KiB | 92 KiB/</span>s, done.</span><br><span class="line">Resolving <span class="string">deltas:</span> <span class="number">100</span>% (<span class="number">211</span>/<span class="number">211</span>), completed with <span class="number">72</span> local objects.</span><br><span class="line">From <span class="string">git:</span><span class="comment">//github.com/huacnlee/ruby-china</span></span><br><span class="line"> * [<span class="keyword">new</span> branch]      master -&gt; huacnlee/master</span><br><span class="line"># 将 huacnlee 的 master 分支的改动合并过来,目前是处与 master 分支</span><br><span class="line"><span class="regexp">~/work/</span>ruby-china &lt;master&gt; $ git merge huacnlee/master</span><br></pre></td></tr></table></figure>
<p>Git中从远程的分支获取最新的版本到本地有这样2个命令：</p>
<ul>
<li>git fetch：相当于是从远程获取最新版本到本地，不会自动merge</li>
</ul>
<figure class="highlight fortran"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git fetch origin master</span><br><span class="line">git <span class="built_in">log</span> -p master..origin/master</span><br><span class="line">git <span class="built_in">merge</span> origin/master</span><br></pre></td></tr></table></figure>
<p>以上命令的含义：<br>首先从远程的origin的master主分支下载最新的版本到origin/master分支上，然后比较本地的master分支和origin/master分支的差别，最后进行合并</p>
<p>上述过程其实可以用以下更清晰的方式来进行：</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">git</span> <span class="tag">fetch</span> <span class="tag">origin</span> <span class="rule"><span class="attribute">master</span>:<span class="value">tmp</span><br><span class="line">git diff tmp </span><br><span class="line">git merge tmp</span></span></span><br></pre></td></tr></table></figure>
<p>从远程获取最新的版本到本地的test分支上,之后再进行比较合并</p>
<ul>
<li>git pull：相当于是从远程获取最新版本并merge到本地</li>
</ul>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="title">git</span> pull origin master</span><br></pre></td></tr></table></figure>
<p>上述命令其实相当于git fetch 和 git merge, 在实际使用中，git fetch更安全一些,因为在merge前，我们可以查看更新情况，然后再决定是否合并</p>
<p>一个教程：<a href="http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000" target="_blank" rel="external">http://www.liaoxuefeng.com/wiki/0013739516305929606dd18361248578c67b8067c8c017b000</a></p>

      
    </div>
    <footer class="article-footer">
	  
	  <!-- 百度分享 Start -->
	  <div class="bdsharebuttonbox"><a href="#" class="bds_more" data-cmd="more"></a><a href="#" class="bds_qzone" data-cmd="qzone" title="分享到QQ空间"></a><a href="#" class="bds_tsina" data-cmd="tsina" title="分享到新浪微博"></a><a href="#" class="bds_tqq" data-cmd="tqq" title="分享到腾讯微博"></a><a href="#" class="bds_renren" data-cmd="renren" title="分享到人人网"></a><a href="#" class="bds_weixin" data-cmd="weixin" title="分享到微信"></a></div>
	  <!-- 百度分享 End -->
	  
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Git/">Git</a></li></ul>

	  
<span>
Updated:<time datetime="2015-03-05T14:43:18.000Z" itemprop="dateModified">2015-03-05</time>
</span>


    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2013/05/09/ubuntu-soft-list/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          Ubuntu软件列表
        
      </div>
    </a>
  
  
    <a href="/2013/04/29/reset-forgot-mysql-root-password/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">Ubuntu下重置忘记的MySql root密码</div>
    </a>
  
</nav>

  
</article>



<!-- 多说评论框 start -->

<section id="comments">
  <div class="ds-thread"  data-thread-key="/2013/05/02/git-note/" data-title="Git学习笔记" data-url="http://howiefh.github.io/2013/05/02/git-note/" id="ds_thread">
    <noscript>Please enable JavaScript to view the <a href="//duoshuo.com/?ref_noscript">comments powered by duoshuo.</a></noscript>
  </div>
</section>

<!-- 多说评论框 end -->
</section>
        
          
  <div id="toc" class="toc-aside">
  <h2 class="toc-title">Contents</h2>
    
        <ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#git别名"><span class="toc-number">1.</span> <span class="toc-text">git别名</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#忽略文件"><span class="toc-number">2.</span> <span class="toc-text">忽略文件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#添加文件到暂存区"><span class="toc-number">3.</span> <span class="toc-text">添加文件到暂存区</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#提交修改"><span class="toc-number">4.</span> <span class="toc-text">提交修改</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#查看工作目录状态"><span class="toc-number">5.</span> <span class="toc-text">查看工作目录状态</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#查看文件改动"><span class="toc-number">6.</span> <span class="toc-text">查看文件改动</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#查看提交信息"><span class="toc-number">7.</span> <span class="toc-text">查看提交信息</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#反转提交"><span class="toc-number">8.</span> <span class="toc-text">反转提交</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#克隆远程版本库"><span class="toc-number">9.</span> <span class="toc-text">克隆远程版本库</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#创建分支"><span class="toc-number">10.</span> <span class="toc-text">创建分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#切换分支"><span class="toc-number">11.</span> <span class="toc-text">切换分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#重命名分支"><span class="toc-number">12.</span> <span class="toc-text">重命名分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#合并分支"><span class="toc-number">13.</span> <span class="toc-text">合并分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#删除分支"><span class="toc-number">14.</span> <span class="toc-text">删除分支</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#打标签"><span class="toc-number">15.</span> <span class="toc-text">打标签</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#创建归档文件"><span class="toc-number">16.</span> <span class="toc-text">创建归档文件</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#文件重命名和移动"><span class="toc-number">17.</span> <span class="toc-text">文件重命名和移动</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#合并其他remote上面的更新"><span class="toc-number">18.</span> <span class="toc-text">合并其他remote上面的更新</span></a></li></ol>
    
  </div>

<aside id="sidebar">

  
    
<div class="widget-wrap">
  <h3 class="widget-title">ABOUT ME</h3>
  <ul class="widget about-me">
    
    <li><img class="author" title="About me" src="http://fh-1.qiniudn.com/okal-eltocat.jpg" /></li>
    
    
    <li>Hi,I'm FengHao.</li>
    
    <li>I'll share something interesting and my learning experience with you at this blog.</li>
    
    <li>前博客:<a href="http://hi.baidu.com/idea_star" target="_BLANK">百度空间</a></li>
    
  </ul>
</div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/Android/">Android</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/C/">C</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Database/">Database</a><span class="category-list-count">13</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/Database/MongoDB/">MongoDB</a><span class="category-list-count">10</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Database/MySQL/">MySQL</a><span class="category-list-count">2</span></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/categories/Eclipse/">Eclipse</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/FTP/">FTP</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Git/">Git</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Hexo/">Hexo</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Java/">Java</a><span class="category-list-count">20</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/Java/FreeMarker/">FreeMarker</a><span class="category-list-count">3</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Java/Shiro/">Shiro</a><span class="category-list-count">2</span></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/categories/JavaEE/">JavaEE</a><span class="category-list-count">4</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/JavaEE/Hibernate/">Hibernate</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/JavaEE/JSP/">JSP</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/JavaEE/Spring/">Spring</a><span class="category-list-count">2</span></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/categories/JavaScript/">JavaScript</a><span class="category-list-count">5</span><ul class="category-list-child"><li class="category-list-item"><a class="category-list-link" href="/categories/JavaScript/jQuery/">jQuery</a><span class="category-list-count">1</span></li></ul></li><li class="category-list-item"><a class="category-list-link" href="/categories/Linux/">Linux</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/PHP/">PHP</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Suse/">Suse</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Ubuntu/">Ubuntu</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Vim/">Vim</a><span class="category-list-count">8</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/编程/">编程</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/软件/">软件</a><span class="category-list-count">1</span></li></ul>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Android/" style="font-size: 14.75px; color: #65bfa7">Android</a> <a href="/tags/C/" style="font-size: 13.88px; color: #71c1c2">C</a> <a href="/tags/CAS/" style="font-size: 13px; color: #7dc3de">CAS</a> <a href="/tags/Chrome/" style="font-size: 13px; color: #7dc3de">Chrome</a> <a href="/tags/Clean-Code/" style="font-size: 13.88px; color: #71c1c2">Clean Code</a> <a href="/tags/Database/" style="font-size: 13px; color: #7dc3de">Database</a> <a href="/tags/Eclipse/" style="font-size: 13px; color: #7dc3de">Eclipse</a> <a href="/tags/FTP/" style="font-size: 13.88px; color: #71c1c2">FTP</a> <a href="/tags/FreeMarker/" style="font-size: 14.75px; color: #65bfa7">FreeMarker</a> <a href="/tags/Gcc/" style="font-size: 13px; color: #7dc3de">Gcc</a> <a href="/tags/Git/" style="font-size: 14.75px; color: #65bfa7">Git</a> <a href="/tags/Github-Pages/" style="font-size: 13px; color: #7dc3de">Github Pages</a> <a href="/tags/Hexo/" style="font-size: 14.75px; color: #65bfa7">Hexo</a> <a href="/tags/Hibernate/" style="font-size: 13px; color: #7dc3de">Hibernate</a> <a href="/tags/JSP/" style="font-size: 13px; color: #7dc3de">JSP</a> <a href="/tags/JVM/" style="font-size: 14.75px; color: #65bfa7">JVM</a> <a href="/tags/Java/" style="font-size: 14.75px; color: #65bfa7">Java</a> <a href="/tags/JavaMail/" style="font-size: 13px; color: #7dc3de">JavaMail</a> <a href="/tags/JavaScript/" style="font-size: 16.5px; color: #4dbc6f">JavaScript</a> <a href="/tags/Linux/" style="font-size: 13.88px; color: #71c1c2">Linux</a> <a href="/tags/Log/" style="font-size: 13px; color: #7dc3de">Log</a> <a href="/tags/Markdown/" style="font-size: 13.88px; color: #71c1c2">Markdown</a> <a href="/tags/MongoDB/" style="font-size: 20px; color: #1db400">MongoDB</a> <a href="/tags/MySQL/" style="font-size: 13.88px; color: #71c1c2">MySQL</a> <a href="/tags/PHP/" style="font-size: 16.5px; color: #4dbc6f">PHP</a> <a href="/tags/Rhythmbox/" style="font-size: 13px; color: #7dc3de">Rhythmbox</a> <a href="/tags/SSO/" style="font-size: 13px; color: #7dc3de">SSO</a> <a href="/tags/Servlet/" style="font-size: 13px; color: #7dc3de">Servlet</a> <a href="/tags/Shiro/" style="font-size: 13.88px; color: #71c1c2">Shiro</a> <a href="/tags/Spring/" style="font-size: 13.88px; color: #71c1c2">Spring</a> <a href="/tags/Suse/" style="font-size: 13px; color: #7dc3de">Suse</a> <a href="/tags/Thinking-in-Java/" style="font-size: 19.13px; color: #29b61c">Thinking in Java</a> <a href="/tags/Ubuntu/" style="font-size: 17.38px; color: #41ba53">Ubuntu</a> <a href="/tags/Vim/" style="font-size: 18.25px; color: #35b838">Vim</a> <a href="/tags/VirtualBox/" style="font-size: 13px; color: #7dc3de">VirtualBox</a> <a href="/tags/Vsftpd/" style="font-size: 13px; color: #7dc3de">Vsftpd</a> <a href="/tags/jQuery/" style="font-size: 13px; color: #7dc3de">jQuery</a> <a href="/tags/pam-mysql/" style="font-size: 13px; color: #7dc3de">pam_mysql</a> <a href="/tags/小米/" style="font-size: 13px; color: #7dc3de">小米</a> <a href="/tags/软件/" style="font-size: 15.63px; color: #59bd8b">软件</a>
    </div>
  </div>


  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/09/">September 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/08/">August 2015</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/07/">July 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/05/">May 2015</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/04/">April 2015</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/03/">March 2015</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/02/">February 2015</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/12/">December 2014</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/11/">November 2014</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/10/">October 2014</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/09/">September 2014</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/08/">August 2014</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/07/">July 2014</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/06/">June 2014</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/05/">May 2014</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/04/">April 2014</a><span class="archive-list-count">4</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/03/">March 2014</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/02/">February 2014</a><span class="archive-list-count">11</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2014/01/">January 2014</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/12/">December 2013</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/11/">November 2013</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/08/">August 2013</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/07/">July 2013</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/06/">June 2013</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/05/">May 2013</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2013/04/">April 2013</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2012/03/">March 2012</a><span class="archive-list-count">1</span></li></ul>
    </div>
  </div>


  
    <div class="widget-wrap">
  <h3 class="widget-title">Calendar</h3>
  <div class="widget">
    <div id="g-calendar" class="g-calendar">
        <span class="g-calendar-prev"></span>
		 
        <span class="g-calendar-back"></span>
        <span class="g-calendar-now"></span>
		 
        <span class="g-calendar-next"></span>
        <div class="g-calendar-hd"></div>
        <div class="g-calendar-tit"></div>
        <div class="g-calendar-bd"></div>
    </div>
  </div>
</div>
<script type="text/javascript">
function LGY_calendar(wrapId, options){
    this.oWrap = this.getId(wrapId);
    this.oHead = this.getByClassName('g-calendar-hd',this.oWrap)[0];
    this.oBody = this.getByClassName('g-calendar-bd',this.oWrap)[0];
    this.oTit = this.getByClassName('g-calendar-tit',this.oWrap)[0];
    this.oPrev = this.getByClassName('g-calendar-prev',this.oWrap)[0];
    this.oNext = this.getByClassName('g-calendar-next',this.oWrap)[0];
    this.oNow = this.getByClassName('g-calendar-now',this.oWrap)[0];
    this.oBack = this.getByClassName('g-calendar-back',this.oWrap)[0];
    this.init();
}
LGY_calendar.prototype = {
    ///////////获取ID元素
    getId:function(id){
        return document.getElementById(id);
    },
    ////////获取css类名元素
    getByClassName:function(className,parent){
        var elem = [],
            node = parent != undefined&&parent.nodeType==1?parent.getElementsByTagName('*'):document.getElementsByTagName('*'),
            p = new RegExp("(^|\\s)"+className+"(\\s|$)");
        for(var n=0,i=node.length;n<i;n++){
            if(p.test(node[n].className)){
                elem.push(node[n]);
            }
        }
        return elem;
    },
    //填充日历
    fillDate:function(year,month){
        //本月份第一天是星期几-为显示上个月的天数做铺垫
        var first_day = new Date(year,month,1).getDay(),
        //如果刚好是星期天，则空出一行（显示上个月的天数）
            first_day = first_day == 0?first_day=7:first_day;
        //本月份最后一天是几号
        var final_date = new Date(year,month+1,0).getDate(),
        //上个月的最后一天是几号
            last_date = new Date(year,month,0).getDate(),
        //剩余的格子数--即排在末尾的格子数
            surplus = 42 - first_day - final_date;
        //设置年的链接
        var yearHead = "<a href='/" + "archives/" + year + "/'>" + year + " "+ "</a>"; 
        //设置年的链接
        var monthHead = "";
        var month1 = month + 1;
        if (month1 < 10) {
            monthHead = "<a href='/" + "archives/" + year + "/" + "0" + month1 + "/'>" + " " + month1 + " " + "</a>";
        } else {
            monthHead = "<a href='/" + "archives/" + year + "/" + month1 + "/'>" + " " + month1 + " " + "</a>";
        }
        //设置表头的日历
        this.oHead.innerHTML = yearHead+'年'+monthHead+'月';
        //填充日历执行
        var html = '';
        //上个月的显示天数
        for(var i=0;i<first_day;i++){
            html+='<span class="g-calendar-grey">'+(last_date-(first_day-1)+i)+'</span>';
        }
        //本月的显示天数
        var postdate = new Date("Thu May 02 2013 18:31:29 GMT+0800"); 
        if (true && postdate.getFullYear() == year && postdate.getMonth() == month) { 
            html += '<span>1</span><span><a href="/2013/05/02/git-note/" title="Git学习笔记">2</a></span><span>3</span><span>4</span><span>5</span><span>6</span><span>7</span><span>8</span><span><a href="/2013/05/09/ubuntu-soft-list/" title="Ubuntu软件列表">9</a></span><span>10</span><span>11</span><span>12</span><span>13</span><span>14</span><span>15</span><span><a href="/2013/05/16/vim-markdown-preview/" title="vim编辑markdown时实现预览">16</a></span><span><a href="/2013/05/17/make-tagbar-support-markdown/" title="让tagbar支持markdown">17</a></span><span>18</span><span>19</span><span><a href="/2013/05/20/plans-for-vim-7.4/" title="Vim 7.4 计划已公布">20</a></span><span>21</span><span>22</span><span>23</span><span>24</span><span>25</span><span>26</span><span>27</span><span>28</span><span>29</span><span>30</span>';
        } else {
            for(var j=0;j<final_date;j++){        
                html+='<span id="d'+(j+1)+'">'+(j+1)+'</span>';
            }
        }
        //下个月的显示天数
        for(var k=0;k<surplus;k++){
            html+='<span class="g-calendar-grey">'+(k+1)+'</span>';
        }
        //fill
        this.oBody.innerHTML = html;
        // 当前状态
        if(year==this.c_year&&this.c_month==month){
            this.oBody.getElementsByTagName('span')[first_day+this.date-1].className='g-calendar-on';
        }

        // 对所有文章遍历,然后将有文章的日期加上链接,如果文章太多的话,生成页面会很大,去掉了
        
    },
    // next切换
    next:function(){
        var _that = this;
        this.oNext.onclick = function(){
            _that.month++;
            if(_that.month>11){
                _that.month = 0;
                _that.year++;
            }
            // 填充日历
            _that.fillDate(_that.year,_that.month);
        };
    },
    // back 切换
    back:function(){
        var _that = this;
        if(this.oBack != undefined) {
            this.oBack.onclick = function(){
                var postdate = new Date("Thu May 02 2013 18:31:29 GMT+0800"); 
                _that.year = postdate.getFullYear();
                _that.month = postdate.getMonth();
                // 填充日历
                _that.fillDate(_that.year,_that.month);
            };
        }
    },
    // now切换
    now:function(){
        var _that = this;
        if(this.oNow != undefined ) {
            this.oNow.onclick = function(){
                var nowDate = new Date(); 
                _that.year = nowDate.getFullYear();
                _that.month = nowDate.getMonth();
                // 填充日历
                _that.fillDate(_that.year,_that.month);
            };
        }
    },
    // prev切换
    prev:function(){
        var _that = this;
        this.oPrev.onclick = function(){
            _that.month--;
            if(_that.month<0){
                _that.month = 11;
                _that.year--;
            }
            // 填充日历
            _that.fillDate(_that.year,_that.month);
        };
    },
    init:function(){
        this.oTit.innerHTML = '<span>日</span><span>一</span><span>二</span><span>三</span><span>四</span><span>五</span><span>六</span>';
        // 获取今天的日历时间
        var now = new Date();
        this.c_year = this.year = now.getFullYear();
        this.c_month = this.month = now.getMonth();
        this.date = now.getDate();
        // 初始化--填充日历
        this.fillDate(this.year,this.month);
        //next切换
        this.next();
        //prev切换
        this.prev();
        //back 切换
        this.back();
        //now 切换
        this.now();
    }
}
new LGY_calendar('g-calendar');
</script>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recent Posts</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2015/09/01/javascript-summary/">JavaScript 总结</a>
          </li>
        
          <li>
            <a href="/2015/08/28/javascript-oop-function-expression-and-async/">JavaScript 面向对象程序设计、函数表达式和异步编程</a>
          </li>
        
          <li>
            <a href="/2015/08/28/javascript-reference-type/">JavaScript 引用类型</a>
          </li>
        
          <li>
            <a href="/2015/08/28/javascript-grammar/">JavaScript 基本语法</a>
          </li>
        
          <li>
            <a href="/2015/08/10/java-web/">Java Web 笔记</a>
          </li>
        
      </ul>
    </div>
  </div>


  
    
<div class="widget-wrap">
  <h3 class="widget-title">Recent Comments</h3>
  <ul class="widget ds-recent-comments" data-num-items="5" data-show-avatars="0" data-show-title="1" data-show-time="1"></ul>
</div>
<!-- 需要多说的公用代码 -->


  

</aside>

        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2015 howiefh<br>
      Powered by <a href="http://zespia.tw/hexo/" target="_blank">Hexo</a> and Theme by <a href="https://github.com/howiefh/hexo-theme-landscape-f" target="_blank" title="Landscape-F">Landscape-F</a>
    </div>
  </div>
</footer>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
</nav>
    

<!-- 多说公共JS代码 start (一个网页只需插入一次) -->

<script type="text/javascript">
  var duoshuoQuery = {short_name:"howiefh"};
  (function() {
	var ds = document.createElement('script');
	ds.type = 'text/javascript';ds.async = true;
	ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
	ds.charset = 'UTF-8';
	(document.getElementsByTagName('head')[0] 
		|| document.getElementsByTagName('body')[0]).appendChild(ds);
  })();
</script> 

<!-- 多说公共JS代码 end -->

<!-- 百度分享 start -->

<script>window._bd_share_config={"common":{"bdSnsKey":{},"bdText":"","bdMini":"2","bdMiniList":["mshare","douban","bdysc","sqq","qq","hi","baidu","huaban","youdao","sdo","mail","xg","diandian","fx","copy","print"],"bdPic":"","bdStyle":"1","bdSize":"16"},"share":{},"image":{"viewList":["qzone","tsina","tqq","renren","weixin"],"viewText":"分享到：","viewSize":"16"}};with(document)0[(getElementsByTagName('head')[0]||body).appendChild(createElement('script')).src='http://bdimg.share.baidu.com/static/api/js/share.js?v=89860593.js?cdnversion='+~(-new Date()/36e5)];</script>

<!-- 百度分享 end -->

<!--
<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
<script src="/js/jquery.min.js"></script>
-->
<script src="/js/jquery.min.js" type="text/javascript"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css" type="text/css">
  <script src="/fancybox/jquery.fancybox.pack.js" type="text/javascript"></script>


<div class="bottom-btn">

	<a class="icon-gotop" href="javascript:void(0)" title="返回顶部"></a>
	<script src="/js/gotop.js" type="text/javascript"></script>
	<!--
	<script src="/js/gotop.js"></script>
	-->


	<a class="icon-toc-toggle" href="javascript:void(0)" title="文章目录"></a>
	<!--
	<script src="/js/toc_aside_toggle.js"></script>
	-->

</div>
<script src="/js/toc_aside_toggle.js" type="text/javascript"></script>


<script src="/js/script.js" type="text/javascript"></script>

  </div>
</body>
</html>
